using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.HttpOverrides;

namespace Idp_Login.Configs
{
    public static class ProxyConfig
    {
        /// <summary>
        /// 必需在app.UseHsts(); 之前
        /// </summary>
        /// <param name="app"></param>
        /// <returns></returns>
        public static IApplicationBuilder ConfigureHttpsForwardingBehindProxy(this IApplicationBuilder app)
        {

            var fordwardedHeaderOptions = new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            };
            fordwardedHeaderOptions.KnownNetworks.Clear();
            fordwardedHeaderOptions.KnownProxies.Clear();

            app.UseForwardedHeaders(fordwardedHeaderOptions); //必需在app.UseHsts(); 之前
            return app;
        }
    }
}